package main.userInterface;

import main.demonutils.io.IslandIOController;
import main.model.hexisland.DefaultHexIsland;
import main.model.hexisland.HexIsland;
import main.userInterface.hexislandui.HexIslandCanvas;

import javax.swing.*;
import java.awt.*;
import java.io.File;

/**
 * Created with IntelliJ IDEA.
 * User: gabe
 * Date: 02/07/13
 * Time: 19:45
 * To change this template use File | Settings | File Templates.
 */
public class BuildIslandSet extends JFrame {

    private final JLabel explainLab = new JLabel("This Directory contains the following files:");
    private JList<String> choicesArea;
    private JButton chooseFolderButton = new JButton("Choose Directory");

    private File[] dirContent = null;
    private JButton loadIslandButton = new JButton("Load File");
    private JButton editIslandButton = new JButton("Launch Island Editor");

    public BuildIslandSet(){
        super("WALLACE'S ISLAND Critters");
        setSize(900,600);
        setResizable(true);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);


        this.add(buildIslandChooser());

        //House Keeping
        //validateTree();
        //pack();
        setVisible(true);
        toFront();
    }


    public static void main(String args[]) throws Exception {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        BuildIslandSet thegui = new BuildIslandSet();
    }


    public JPanel buildIslandChooser(){
        JPanel islandChooser = new JPanel();
        islandChooser.setLayout(new BoxLayout(islandChooser,BoxLayout.PAGE_AXIS));

        HexIsland hexIsland = new DefaultHexIsland();
        IslandIOController islandIOController = new IslandIOController(hexIsland);

        JPanel choicesPanel = new JPanel();
        choicesPanel.setLayout(new BoxLayout(choicesPanel,BoxLayout.PAGE_AXIS));

        choicesPanel.add(explainLab);

        choicesArea = new JList<String>();
        choicesArea.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        choicesArea.setLayoutOrientation(JList.VERTICAL);
        choicesArea.setVisibleRowCount(8);

        JScrollPane choicesScroll = new JScrollPane(choicesArea);
        choicesScroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        choicesScroll.setAlignmentX(Component.CENTER_ALIGNMENT);

        choicesPanel.add(choicesScroll);

        chooseFolderButton.setAlignmentX(Component.RIGHT_ALIGNMENT);

        choicesPanel.add(chooseFolderButton);


        choicesPanel.add(loadIslandButton);


        HexIslandCanvas hexIslandCanvas = new HexIslandCanvas(hexIsland);
        hexIslandCanvas.setZoom(8);
        JScrollPane islandScrollPane = new JScrollPane(hexIslandCanvas);
        JPanel islandPreview = new JPanel();
        islandPreview.setLayout(new BoxLayout(islandPreview,BoxLayout.PAGE_AXIS));
        islandPreview.add(islandScrollPane);
        islandPreview.add(editIslandButton);

        islandChooser.add(choicesPanel);
        islandChooser.add(islandPreview);
        islandChooser.setBorder(BorderFactory.createTitledBorder("Island Preview"));
        return islandChooser;
    }

}
